package com.file.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.entity.Meter;
import com.file.entity.FileMeter;
import com.file.service.MeterService;
import com.setting.service.SysdicService;
import com.utils.JsonResult;
import com.utils.JsonSysdic;

/**
 * @Title: MeterController.java
 * @Package com.controller
 * @author 孙梦楠
 * @date 2017年7月21日 上午11:38:25
 * @version V1.0.0
 */
@RestController
@RequestMapping(value = "/file/meter")
public class MeterController {

	@Autowired
	private MeterService meterservice;

	@Autowired
	private SysdicService sysdicservice;

	

	// 条件列表
	@RequestMapping(value = "", method = RequestMethod.POST)
	public JsonResult<List<FileMeter>> listMeterByConditions(@RequestBody Meter meter,
			@CookieValue(value = "opeorgcookie", required = false) String opeorgcookie,
			@CookieValue(value = "opetypecookie", required = false) String opetypecookie,
			@CookieValue(value = "languagecookie", required = false) String languagecookie) {

		String metercode = meter.getMetercode();
		String meterassetcode = meter.getMeterassetcode();
		String metertype = meter.getMetertype();
		String meteraddress = meter.getMeteraddress();
		String meterprotocol = meter.getMeterprotocol();
		String metermade = meter.getMetermade();
		String meterstatus = meter.getMeterstatus();
		String meterpassword = meter.getMeterpassword();

		return meterservice.listMeterByConditions(metercode, meterassetcode, metertype, meteraddress, meterprotocol,
				metermade, opeorgcookie, opetypecookie,meterstatus, meterpassword,languagecookie);

	}

	// 字典列表

	@RequestMapping(value = "/listsysdicMetertype", method = RequestMethod.GET)
	public JsonResult<List<JsonSysdic>> listsysdicMetertype(
			@CookieValue(value = "opetypecookie", required = false) String opetypecookie,
			@CookieValue(value = "languagecookie", required = false) String languagecookie) {

		String sysdictype = sysdicservice.gettype(opetypecookie, "3");//表  3
		Integer state = 222;
		String Message = "Metertype字段列表";

		return sysdicservice.listsysdic(sysdictype, state, Message,languagecookie);
	}

	@RequestMapping(value = "/listsysdicMeterprotocol", method = RequestMethod.GET)
	public JsonResult<List<JsonSysdic>> listsysdicMeterprotocol(
			@CookieValue(value = "languagecookie", required = false) String languagecookie) {

		String sysdictype = "0011";
		Integer state = 223;
		String Message = "Meterprotocol字段列表";

		return sysdicservice.listsysdic(sysdictype, state, Message,languagecookie);
	}

	@RequestMapping(value = "/listsysdicMetermade", method = RequestMethod.GET)
	public JsonResult<List<JsonSysdic>> listsysdicMetermade(
			@CookieValue(value = "languagecookie", required = false) String languagecookie) {

		String sysdictype = "0008";
		Integer state = 224;
		String Message = "Metermade字段列表";

		return sysdicservice.listsysdic(sysdictype, state, Message,languagecookie);
	}

	@RequestMapping(value = "/listsysdicMeterstatus", method = RequestMethod.GET)
	public JsonResult<List<JsonSysdic>> listsysdicMeterstatus(
			@CookieValue(value = "languagecookie", required = false) String languagecookie) {

		String sysdictype = "0009";
		Integer state = 225;
		String Message = "Meterstatus字段列表";

		return sysdicservice.listsysdic(sysdictype, state, Message,languagecookie);
	}

	// 增加
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	public JsonResult<Meter> addmeter(@RequestBody Meter meter,
			@CookieValue(value = "opeorgcookie", required = false) String opeorgcookie,
			@CookieValue(value = "opetypecookie", required = false) String opetypecookie) {

		String metercode = meter.getMetercode();
		String meterassetcode = meter.getMeterassetcode();
		String metertype = meter.getMetertype();
		String meteraddress = meter.getMeteraddress();
		String meterprotocol = meter.getMeterprotocol();
		String metermade = meter.getMetermade();
		String meterpassword = meter.getMeterpassword();
		Integer metermultiple = meter.getMetermultiple();
		String meterphysicaladdress = meter.getMeterphysicaladdress();
		String meterkeytype= meter.getMeterkeytype();

		return meterservice.addmeter(metercode, meterassetcode, metertype, meteraddress, meterprotocol, metermade,
				opeorgcookie, meterpassword,opetypecookie,metermultiple,meterphysicaladdress,meterkeytype);

	}

	// 删除
	@RequestMapping(value = "/delete", method = RequestMethod.POST)
	public JsonResult<Meter> deletemeter(@RequestBody Meter meter) {

		Integer meterid = meter.getMeterid();

		return meterservice.deletemeter(meterid);

	}
	//强制删除
	@RequestMapping(value = "/force_delete", method = RequestMethod.POST)
	public JsonResult<Meter> force_deletemeter(@RequestBody Meter meter) {

		Integer meterid = meter.getMeterid();

		return meterservice.forcedeletemeter(meterid);

	}

	// 修改页面
	@RequestMapping(value = "/getbyid", method = RequestMethod.POST)
	public JsonResult<FileMeter> updatemeter(@RequestBody Meter meter,
			@CookieValue(value = "languagecookie", required = false) String languagecookie) {

		Integer meterid = meter.getMeterid();

		return meterservice.updateviewmeter(meterid,languagecookie);
	}

	// 修改
	@RequestMapping(value = "/update", method = RequestMethod.POST)
	public JsonResult<Meter> updatemeter(@RequestBody Meter meter,
			@CookieValue(value = "opeorgcookie", required = false) String opeorgcookie,
			@CookieValue(value = "opetypecookie", required = false) String opetypecookie) {

		Integer meterid = meter.getMeterid();
		String metercode = meter.getMetercode();
		String meterassetcode = meter.getMeterassetcode();
		String metertype = meter.getMetertype();
		String meteraddress = meter.getMeteraddress();
		String meterprotocol = meter.getMeterprotocol();
		String metermade = meter.getMetermade();
		String meterstatus = null;
		String meterpassword = meter.getMeterpassword();
		Integer metermultiple = meter.getMetermultiple();
		String meterphysicaladdress = meter.getMeterphysicaladdress();
		String meterkeytype= meter.getMeterkeytype();

		return meterservice.updatemeter(meterid, metercode, meterassetcode, metertype, meteraddress, meterprotocol,
				metermade, opeorgcookie, meterstatus, meterpassword,opetypecookie,metermultiple,meterphysicaladdress,meterkeytype);

	}

}
